package ssf.app.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.*;
import ssf.app.service.EmployeeService;
import ssf.app.service.ServiceManager;
import ssf.core.common.PagingList;

// Referenced classes of package ssf.app.action:
//            BaseAction

public class EmployeeAction extends BaseAction
{

    public EmployeeAction()
    {
    }

    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws Exception
    {
        String action = request.getParameter("action");
        if(action == null)
            return other(mapping, form, request, response);
        if("employeelist".equals(action))
            return list(mapping, form, request, response);
        if("viewadd".equals(action))
            return viewadd(mapping, form, request, response);
        else
            return other(mapping, form, request, response);
    }

    public ActionForward list(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws Exception
    {
        PagingList employeeList = getServMgr().getEmployeeService().getAllEmployees(request);
        request.setAttribute("employeelist", employeeList);
        request.setAttribute("URL", request.getRequestURI() + "?action=employeelist");
        return mapping.findForward("employeelist");
    }

    public ActionForward viewadd(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws Exception
    {
        return mapping.findForward("viewadd");
    }

    public ActionForward other(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws Exception
    {
        setResult(request, "ERROR");
        addMessage(request, "未定义操作，请返回!");
        addRedirURL(request, "返回", "@back");
        return mapping.findForward("EXECUTE_RESULT");
    }
}
